package com.jiujichina.controller;

import com.jiujichina.base.Meta;
import com.jiujichina.base.ResultData;
import com.jiujichina.exception.BizException;
import com.jiujichina.model.TbUser;
import com.jiujichina.service.UserService;
import com.jiujichina.service.impl.UserServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user")
@Api("UserController相关的api")
public class UserController {

	@Autowired
	UserService userService;

	Logger logger = Logger.getLogger(UserController.class);

	/**
	 * 根据ID查询用户
	 * @param id
	 * @return
	 */
	@ApiOperation(value="获取用户详细信息", notes="根据url的id来获取用户详细信息")
	@ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Integer", paramType = "path")
	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	public ResultData getUserById (@PathVariable(value = "id") Integer id){
		TbUser tbUser = userService.getById(id);
		return new ResultData(Meta.CODE_200.getCode(),tbUser);
	}

	@ApiOperation(value="获取用户详细信息", notes="根据url的id来获取用户详细信息")
	@RequestMapping(value = "/", method = RequestMethod.GET)
	public ResultData getList (){
		List<TbUser> tbUsers = userService.getList();
		return new ResultData(Meta.CODE_200.getCode(),tbUsers);
	}

	@ApiOperation(value="获取分支", notes="获取分支")
	@RequestMapping(value = "/test", method = RequestMethod.GET)
	public ResultData getTest (){
		return new ResultData(Meta.CODE_200.getCode(),"我是主分支");
	}


	
}
